package com.hhp.hhptt.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.hhp.hhptt.service.IRoleService;
import com.hhp.hhptt.entity.Role;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhp
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/role")
public class RoleController {



@Resource
private IRoleService roleService;


@PostMapping("/save")
public Boolean save(@RequestBody Role role) {
        return roleService.saveOrUpdate(role);
        }

@DeleteMapping("/delete/{id}")
public Boolean delete(@PathVariable Integer id) {
        return roleService.removeById(id);
        }
@PostMapping("/deleteBatch")
public Boolean deleteBatch(@RequestBody List<Integer> ids) {
        return roleService.removeByIds(ids);
        }

@GetMapping("/getAll")
public List<Role> findAll() {
        return roleService.list();
        }
@GetMapping("/{id}")
public Role findOne(@PathVariable Integer id) {
        return roleService.getById(id);
        }

@GetMapping("/page")
public Page<Role> findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String name) {

        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if(!"".equals(name)){
                queryWrapper.like("name",name);
        }
        queryWrapper.orderByDesc("id");
        return roleService.page(new Page<>(pageNum, pageSize),queryWrapper);
        }
        }

